package com.ittest.mapper.store;

import com.ittest.domain.store.Member;
import com.ittest.domain.store.Orders;
import com.ittest.domain.store.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrdersMapper {
    //添加
    @Insert("insert into orders id,orderNum,orderTime,peopleCount,ordersDesc,payType,orderStatus,productId,memberId" +
            "  values (#{id},#{orderNum},#{orderTime},#{peopleCount},#{orderDesc},#{orderStatus},#{product.id},#{member.id})")
    int add(Orders orders);

    //修改
    int update(Orders orders);

    //删除
    int delete(String[] ids);

    //查询所有
    @Select("select * from orders")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "orderDesc",property = "orderDesc"),
            @Result(column = "orderStatus",property = "orderStatus"),
            @Result(property = "product",javaType = Product.class,column = "productId",
                    one=@One(select = "com.ittest.mapper.store.ProductMapper.findById")),
            @Result(property = "member",javaType = Member.class,column = "memberId",
                    one=@One(select = "com.ittest.mapper.store.MemberMapper.findById"))
    })
    List<Orders> findAll();

    //根据id查询
    @Select("select * from orders where id=#{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "orderDesc",property = "orderDesc"),
            @Result(column = "orderStatus",property = "orderStatus"),
            @Result(property = "product",javaType = Product.class,column = "productId",
                   one = @One(select = "com.ittest.mapper.store.ProductMapper.findById")),
            @Result(property = "member",javaType = Member.class,column = "memberId",
                    one=@One(select = "com.ittest.mapper.store.MemberMapper.findById")),
            @Result(property = "travellers",javaType = List.class,column = "id",
            many = @Many(select = "com.ittest.mapper.store.TravellerMapper.findByOrderId"))
    })
    Orders findById(String id);
}
